package simulation;
import java.io.PrintStream;

public class Statistics {
	int n;
	double sum, sqsum, min, max;
	
	
	
	public Statistics(){
		n = 0;
		sum = 0;
	}

	public void add(double v){
		sum += v;
		sqsum += v * v;
		if (n == 0) {
			min = max = v;
		}
		else {
			if (v < min) {
				min = v;
			}
			if (v > max) {
				max = v;
			}
		}
		n++;
	}

	public int count(){
		return n;
	}

	public double avg(){
		if (n==0) return 0 ;
		return sum / n;
	}

	public double mean(){
		return sum / n;
	}

	public double sum(){
		return sum;
	}

	public double min(){
		return min;
	}

	public double max(){
		return max;
	}

	public double stdev(){
		if (n==0) return 0 ;
		double sum2 = sum * sum / n;
		if (sqsum <= sum2) {
			return 0;
		}
		return Math.sqrt((sqsum - sum2) / n / (n - 1));
	}

	void dump(PrintStream out){
		double avg = avg();
		//double c95 = conf_interval(.95);
		//double c99 = conf_interval(.99);
		//out.print(" " + avg + " " + (avg - c95) + " " + (avg + c95) +
	    //				" " + (avg - c99) + " " + (avg + c99) + " " + max());
		out.print(" " + avg + " " + max());
	}
		
	String dump(){
		double avg = avg();
		//double c95 = conf_interval(.95);
		//double c99 = conf_interval(.99);
		String s =" " + avg + " " + max() + " " + sum;
		//String s =" " + avg + " " + max() + " " + sum + " " + stdev() ;
		return s ;
	}
	
	public void printScreen() {
		System.out.println("avg: " + avg()*10);
	}
}